﻿using System;
using Moq;
using NBehave.Spec.NUnit;
using Whisper.CommonTypes;
using Whisper.Interfaces;
using Whisper.Objects;
using Context = NUnit.Framework.TestFixtureAttribute;
using Concerning = NUnit.Framework.CategoryAttribute;
using Specification = NUnit.Framework.TestAttribute;


namespace Whisper.Conversation.Subscription.Specs
{
    [Context, Concerning("Card Service")]
    public class Can_register_conversation_subscription_spec:ServiceBase
    {
        [Specification]
        public void Should_be_able_to_register_a_conversation_with_hub()
        {
            //Prepare
            const string conversationName = "Rebeccas Conversation";
            var createConversationClientViewMock = new Mock<ICreateConversationClientView>();
            createConversationClientViewMock.SetupGet(c => c.ConversationName).Returns(conversationName);
            var retrieveConversationClientViewMock = new Mock<IRetrieveConversationClientView>();
            retrieveConversationClientViewMock.SetupProperty(v=>v.AvailableConversations);
            var adapter = new ConversationServiceAdapter();


            var createConversationClientController = new CreateConversationClientController(adapter, createConversationClientViewMock.Object);
            var retrieveConversationClientController = new RetrieveConversationClientController(adapter, retrieveConversationClientViewMock.Object);


            //DO
            createConversationClientViewMock.Raise(c=>c.SubmitConversation+=null,new EventArgs());
            retrieveConversationClientViewMock.Raise(c => c.RetrieveAvailableSubscriptions += null, new EventArgs());
        
            //Check
            var conversations = retrieveConversationClientViewMock.Object.AvailableConversations;
            conversations.Count.ShouldEqual(1);
            conversations[0].Name.ShouldEqual(conversationName);
        }
    }
}